#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=310,INF=0x3f3f3f3f;
int n,a[MAXN],b[MAXN],d[MAXN],f[MAXN*2][MAXN*2],tmp[MAXN*2],cnt;
map<int,int>mp;
int main()
{
	int T=read();
	while(T--)
	{
		mp.clear();
		cnt=0;
		n=read();
		for(int i=1;i<=n;++i)a[i]=tmp[++cnt]=read(),b[i]=tmp[++cnt]=read(),d[i]=read();
		sort(tmp+1,tmp+1+cnt);
		cnt=unique(tmp+1,tmp+1+cnt)-tmp-1;
		for(int i=1;i<=cnt;++i)
			mp[tmp[i]]=i;
		for(int i=1;i<=n;++i)a[i]=mp[a[i]],b[i]=mp[b[i]];
		++cnt;
		for(int i=1;i<=cnt+1;++i)
			for(int j=0;j+i-1<=cnt;++j)
			{
				f[i][j]=INF;
				int _max=0;
				for(int k=1;k<=n;++k)
					if(a[k]>j&&b[k]<j+i-1&&d[k]>d[_max])
						_max=k;
				if(!_max)
				{
					f[i][j]=0;
					continue;
				}
				for(int k=a[_max];k<=b[_max];++k)
					f[i][j]=min(f[i][j],f[k-j+1][j]+f[j+i-k][k]+d[_max]);
			}
		printf("%d\n",f[cnt+1][0]);
	}
	return 0;
}
